package com.example.demo.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

/**
 * 版权转让记录实体类
 * <p>
 * 用于记录版权转让的历史记录，包括转让双方地址、转让时间和交易状态等信息。
 * 当版权所有权发生转移时，系统会自动创建转让记录。
 * </p>
 */
@Data
@Entity
@Table(name = "copyright_transfer")
@NoArgsConstructor
public class CopyrightTransferEntity {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(name = "copyright_id", nullable = false)
    private Long copyrightId;
    
    @Column(name = "from_address", nullable = false, length = 42)
    private String fromAddress;
    
    @Column(name = "to_address", nullable = false, length = 42)
    private String toAddress;
    
    @Column(name = "transfer_time", nullable = false)
    private Date transferTime;
    
    @Column(name = "tx_hash", length = 66)
    private String txHash;
    
    /**
     * 转让状态：0-进行中，1-成功，2-失败
     */
    @Column(name = "status", nullable = false)
    private Integer status;
    
    @Column(name = "remarks", length = 255)
    private String remarks;
    
    /**
     * 创建版权转让记录
     * @param copyrightId 版权数据库ID
     * @param fromAddress 转让方地址
     * @param toAddress 接收方地址
     * @param txHash 交易哈希
     */
    public CopyrightTransferEntity(Long copyrightId, String fromAddress, String toAddress, String txHash) {
        this.copyrightId = copyrightId;
        this.fromAddress = fromAddress;
        this.toAddress = toAddress;
        this.transferTime = new Date();
        this.txHash = txHash;
        // 默认为进行中
        this.status = 0;
    }
    
    /**
     * 更新交易状态
     * @param status 状态：0-进行中，1-成功，2-失败
     * @param remarks 备注信息
     */
    public void updateStatus(Integer status, String remarks) {
        this.status = status;
        this.remarks = remarks;
    }
} 